home *** CD-ROM | disk | FTP | other *** search
/ SGI Enlighten DSM 3.1 / SGI EnlightenDSM 3.1.iso / DEC3240 / COMMON.Z / COMMON / bin / set_nis_slave < prev    next >
Text File  |  1999-04-16  |  2KB  |  148 lines

  1. #!/bin/sh
  2. #
  3. # Copyright (c) 1990-1999 Enlighten Software Solutions, Inc.
  4. #
  5. # Check arguments: <domain> <master> <start_at_boot> <client_also>
  6. if [ $# -ne 4 ]
  7. then
  8.      exit 1
  9. fi
  10.  
  11. DOMAIN=$1
  12. MASTER=$2
  13. STARTATBOOT=$3
  14. CLIENT=$4
  15.  
  16. # Initialize variables
  17. TMP=/tmp/nissetup.slave.$$
  18. HOSTS=/etc/hosts
  19. RCCONF=/etc/rc.config
  20. ECHO=/bin/echo
  21. RCMGR=/usr/sbin/rcmgr
  22. NISSETUP=/usr/sbin/nissetup
  23. YPDIR=/var/yp
  24.  
  25. # Check if NIS is already configured
  26. prev_conf=`$RCMGR get NIS_CONF`
  27.  
  28. # Check to make sure nissetup won't complain about
  29. # system configuration
  30. if [ \! -w "$RCCONF" ]
  31. then
  32.      exit 2
  33. fi
  34.     
  35. hname=`hostname`
  36. if [ $? -ne 0 ] 
  37. then
  38.      exit 3
  39. fi
  40.  
  41. if [ "$prev_conf" = "YES" ]
  42. then
  43.      exit 4
  44. fi
  45.  
  46. if [ \! -d "$YPDIR" ]
  47. then
  48.      exit 5
  49. fi
  50.  
  51. # Yes, we want to continue 
  52. $ECHO "C" > $TMP
  53.  
  54. # Press ENTER twice
  55. $ECHO "\n" >> $TMP
  56.    
  57. # The host's NIS domain name
  58. $ECHO $DOMAIN >> $TMP
  59. # ... yes, this is the correct NIS domain name
  60. $ECHO "y" >> $TMP
  61.  
  62. # This is going to be a NIS slave server
  63. $ECHO "2" >> $TMP
  64.  
  65. # Copy the current maps from the master server
  66. if [ -d "$YPDIR/$DOMAIN" ]
  67. then
  68.    $ECHO "Y" >> $TMP
  69. fi
  70.  
  71. # Yes, we want to continue 
  72. $ECHO "C" >> $TMP
  73.  
  74. $ECHO $MASTER >> $TMP
  75.  
  76. sed "s/#.*//" $HOSTS > $HOSTS.tmp
  77. good=`egrep "[     ]$MASTER([     \.]|$)" $HOSTS.tmp`
  78. if [ -n "$good" ]
  79. then
  80.    short=`echo $hname | sed 's/\..*//'`
  81.    if [ "$MASTER" = "$hname" ]  || [ "$MASTER" = "$short" ]
  82.    then
  83.       exit 6
  84.    fi
  85. else
  86.    exit 7
  87. fi
  88.  
  89. rm -rf $YPDIR/$DOMAIN
  90. if [ $? -ne 0 ]
  91. then
  92.    exit 8
  93. fi
  94.  
  95. mkdir $YPDIR/$DOMAIN
  96. if [ $? -ne 0 ]
  97. then
  98.    exit 9
  99. fi
  100. rmdir $YPDIR/$DOMAIN
  101.  
  102. # Use the -s security option for ypbind
  103. $ECHO "y" >> $TMP
  104.  
  105. # Use the -S security option for ypbind
  106. $ECHO "y" >> $TMP
  107.  
  108. # Enter (just one) authorized server
  109. $ECHO $MASTER >> $TMP
  110. $ECHO "" >> $TMP
  111.  
  112. # Check to make sure the server name is a correct NIS server name
  113. sed "s/#.*//" $HOSTS > $HOSTS.tmp
  114. good=`egrep "[     ]$MASTER([     \.]|$)" $HOSTS.tmp`
  115. if [ -n "$good" ]
  116. then
  117.    short=`echo $hname | sed 's/\..*//'`
  118.    if [ "$MASTER" = "$hname" ]  || [ "$MASTER" = "$short" ]
  119.    then
  120.       exit 10
  121.    fi
  122. else
  123.    exit 11
  124. fi
  125.  
  126. # Yes, we want to continue 
  127. $ECHO "C" >> $TMP
  128.  
  129. # Disallow all ypset requests
  130. $ECHO "3" >> $TMP
  131.  
  132. # ... yes, this is correct
  133. $ECHO "y" >> $TMP
  134.  
  135. # Use all of the NIS databases served by the NIS server
  136. $ECHO "y" >> $TMP
  137.  
  138. # Start the NIS daemons now
  139. $ECHO "y" >> $TMP
  140.  
  141. # Run the NIS setup utility
  142. cat $TMP | $NISSETUP
  143.  
  144. # Done!
  145. rm $TMP
  146. exit 0
  147.  
  148.